Engine.AscReader = function(input) {

    var gameObject = new Engine.GameObject();

    var re = /(triangle)|((\-?\d+\.?\d+)\s+(\-?\d+\.?\d+)\s+(\-?\d+\.?\d+)\s+(\-?\d+\.?\d+)\s+(\-?\d+\.?\d+)\s+(\-?\d+\.?\d+)\s+(\-?\d+\.?\d+)\s+(\-?\d+\.?\d+))/g;
    var match;
    var triangle = [{},{},{}];
    var normal = [{},{},{}];
    var uv = [{},{},{}];
    var count = 0;
    while (match = re.exec(input)) {
        if (match[1])
        continue;
        triangle[count].x = parseFloat(match[3]);
        triangle[count].y = parseFloat(match[4]);
        triangle[count].z = parseFloat(match[5]);
        normal[count].x = parseFloat(match[6]);
        normal[count].y = parseFloat(match[7]);
        normal[count].z = parseFloat(match[8]);
        uv[count].u = parseFloat(match[9]);
        uv[count].v = parseFloat(match[10]);
        count++;
        if (count >= 3) {
            gameObject.addTriangle(new Engine.Triangle(
            [
                new Engine.Vector3(triangle[0].x,triangle[0].y,triangle[0].z),
                new Engine.Vector3(triangle[1].x,triangle[1].y,triangle[1].z),
                new Engine.Vector3(triangle[2].x,triangle[2].y,triangle[2].z)
            ],
            [
                new Engine.Vector3(normal[0].x,normal[0].y,normal[0].z),
                new Engine.Vector3(normal[1].x,normal[1].y,normal[1].z),
                new Engine.Vector3(normal[2].x,normal[2].y,normal[2].z)
            ],
            [{
                u: uv[0].u,
                v: uv[0].v
            },
            {
                u: uv[1].u,
                v: uv[1].v
            },
            {
                u: uv[2].u,
                v: uv[2].v
            }
            ]
            ));
            count = 0;
        }
    }
    return gameObject;

}

Engine.ObjReader = function(input) {

    var gameObject = new Engine.GameObject();
    var v = [];
    var vt = [];
    var vn = [];
    var lines = input.split("\n");
    for (var i = 0; i < lines.length; i++) {
        var l = lines[i];

        if (l.indexOf("#") != -1) 
            l = l.slice(0, l.indexOf("#"));
        var p = l.split(" ");
        
        if(p[0] == "v"){
            v.push(new Engine.Vector3(parseFloat(p[1]),parseFloat(p[2]),parseFloat(p[3])));
        }
        else if(p[0] == "vt"){
            vt.push({
                u: parseFloat(p[1]),
                v: parseFloat(p[2])
            });
        }
        else if(p[0] == "vn"){
            vn.push(new Engine.Vector3(parseFloat(p[1]),parseFloat(p[2]),parseFloat(p[3])));
        }
        else if(p[0] == "f"){
            var tv = [];
            var tn = [];
            var tt = [];
            
            if(p.length == 4){
                for (var j = 1; j < p.length; j++) {
                    var c = p[j].trim().split("/");
                    tv.push(v[parseInt(c[0]) - 1]);
                    tt.push(vt[parseInt(c[1]) - 1]);
                    tn.push(vn[parseInt(c[2]) - 1]);
                }
                gameObject.triangles.push(new Engine.Triangle(tv,tn,tt));
            }
            else if(p.length == 5){
                
            }
        }
        else{
            
        }
    }

    return gameObject;

}